﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using EDTS.Model.Orgnizations;
using EDTS.Model.Users;
using EDTS.Logic.Orgnizations;
using EDTS.Logic.Users;
namespace EDTS.Logic.Weixin.Messages
{
    internal class TransmitCheck
    {
        /// <summary>
        /// 检查单位信息
        /// </summary>
        /// <param name="unitGuid"></param>
        /// <returns></returns>
        public static UnitModel Unit(Guid unitGuid)
        {
            if (unitGuid == Guid.Empty) throw new Utils.IException("发送单位为空");
            var unit = UnitLogic.GetModel(unitGuid, true);

            if (unit == null) throw new Utils.IException("发送单位无效");
            if (unit.WxApp == null) throw new Utils.IException("此单位还未绑定微信企业号");
            return unit;
        }
        /// <summary>
        /// 检查接收人
        /// </summary>
        /// <param name="receiverGuid"></param>
        /// <returns></returns>
        public static UserModel Receiver(Guid receiverGuid)
        {
            if (receiverGuid == Guid.Empty) throw new Utils.IException("没有接收人。");
            var user = UserLogic.GetModel(receiverGuid);
            if (user == null) throw new Utils.IException("接收人无效");
            if (!user.Interested) throw new Utils.IException("用户未关注");
            return user;
        }
    }
}
